package com.example.activitytest;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

public class SecondActivity extends BaseActivity {
    public static void actionStart(Context context,String data1,String data2){//Context是维持Android程序中各组件能够正常工作的一个核心功能类,Context理解为用户与操作系统交互的一个过程
        Intent intent=new Intent(context,SecondActivity.class);
        intent.putExtra("param1",data1);
        intent.putExtra("param2",data2);
        context.startActivity(intent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        //Log.d("SecondActivity","Task id is"+getTaskId());
        //setContentView(R.layout.second_layout);
        //Intent intent=getIntent();//获取firstactivity中的intent
        //String data=intent.getStringExtra("extra_data");//传入存在intent中的值
        //Log.d("SecondActivity",data);//打印日志
        Button button2=(Button)findViewById(R.id.button_2);
        button2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(SecondActivity.this,ThirdActivity.class);
                intent.putExtra("data_return","Hello,FirstActivity");//intent传数据
                setResult(RESULT_OK,intent);//向上返回数据
                finish();//销毁当前活动
                startActivity(intent);
            }
        });
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        Log.d("SecondActivity","onDestory");
    }
}